 #include <stdio.h>
 #include "mpi.h"
 #define ping 101
 #define pong 101
 float buffer[100000];
int main (int argc, char *argv[]){
    int rank, size; //mpi holders
    int i, j;           //loops
    extern float buffer[100000]; //message buffer
    int length; //loop again
    double start, final, time;
    extern float buffer[100000];


    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
      if(rank!=0){
            MPI_Status status;
          for(i=1;i<size;i++){
           for(length=1;length<=300;length+=10){
            for(j=0;j<100;j++){
             MPI_Recv(buffer, length, MPI_FLOAT, 0, ping, MPI_COMM_WORLD, &status);
             MPI_Send(buffer, length, MPI_FLOAT, 0, pong, MPI_COMM_WORLD);
             }
            }
          }
         }

      if(rank==0){
         MPI_Status status;
         for(i=1;i<size;i++){
           for(length=1;length<=300;length+=10){
            start = MPI_Wtime();
            for(j=0;j<100;j++){
             MPI_Send(buffer, length, MPI_FLOAT, i, ping, MPI_COMM_WORLD);
             MPI_Recv(buffer, length, MPI_FLOAT, MPI_ANY_SOURCE, pong, MPI_COMM_WORLD, &status);
             }
            final = MPI_Wtime();
            time = final-start;
            printf("%s\t%d\t%f\n", "Node", i, time);
            }
         }
     }

 if(rank!=0){
      MPI_Status status;
      for(i=1;i<size;i++){   //<-----------
       for(length=1;length<=300;length+=10){
        for(j=0;j<100;j++){
         MPI_Recv(buffer, length, MPI_FLOAT, 0, ping, MPI_COMM_WORLD, &status);
         MPI_Send(buffer, length, MPI_FLOAT, 0, pong, MPI_COMM_WORLD);
         }
        }
      }                      //<-----------
     }

  MPI_Finalize();
  return 0;
  }